As computers become more adept at displaying graphics, pixels that use 16 bits and 24 bits are becoming more frequently available as input data. However, not all display devices can handle these greater pixel sizes.
Strictly speaking, quantization is the procedure of approximating continuous values with discrete values; in practice, the input values to the quantization procedure are often also discrete, but with a much finer resolution than that of the output values. The goal of quantization usually is to produce a more compact representation of the data while maintaining its usefulness for a certain purpose. For example, to store color intensities you can quantize floating-point values in the range [0.0, 1.0] to integer values in the range 0–255, representing them with 8 bits, which is considered a sufficient resolution for many applications dealing with color. When the spacing of possible values is the same over the entire discrete set, the quantization is said to be uniform. Often, a nonuniform spacing is more appropriate when better resolution is needed over some parts of the range of values.
A problem with quantization is quantization error, which can cause artifacts in the image. Various forms of dithering have been developed to reduce the perceptible results of quantization error.
Error diffusion is a form of dithering in which quanitization errors are diffused to “future” pixels. Error diffusion attempts to spread the error locally. The argument is that, because the error appears close to where it should be, it need not become visible as an artifact in the picture. Originally intended for grayscale images, error diffusion may be extended to color images by error diffusing each of the three color planes independently.
A rough explanation about how error diffusion works is that it takes the red, green, and blue values from the original pixel, finds the best matching pixel in the goal palette, then it finds the difference of the original and final pixel's red, green, and blue values, and adds a fraction of this value to the nearby pixels in the original graphic. In other words, error diffusion reduces local quantization error by filtering the quantization error in a feedback loop. The objective is to balance the red, green, and blue components to make the result look as convincing as possible.